import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:snaplist/snaplist_controller.dart';
import 'package:xm_app/common/http/api_response.dart';
import 'package:xm_app/dao/GankDao.dart';
import 'package:xm_app/model/GankCategoryList.dart';

class GankController extends GetxController {
  GankCategoryListData categoryData;
  SnaplistController snaplistController = SnaplistController();
  int page = 1;

  String type = "normal";
  @override
  void onInit() {
    super.onInit();
    getCategoryData();
  }

  getHotData() async {
    type = "hot";
    ApiResponse<GankCategoryListData> res = await GankDao().getHotCategory(20);
    if (res.status == Status.ERROR) {
      SmartDialog.showToast(res.exception.message);
      return;
    }
    categoryData = res.data;
    update();
  }

  getCategoryData() async {
    page = 1;
    type = "normal";
    ApiResponse<GankCategoryListData> res = await GankDao().getCategory(20, page);
    if (res.status == Status.ERROR) {
      SmartDialog.showToast(res.exception.message);
      return;
    }
    categoryData = res.data;
    update();
  }

  loadMore() async {
    page++;
    ApiResponse<GankCategoryListData> res = await GankDao().getCategory(20, page);
    if (res.status == Status.ERROR) {
      SmartDialog.showToast(res.exception.message);
      return;
    }
    categoryData.data.addAll(res.data.data);
    update();
  }
}
